<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Recmd extends MY_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('topic_model','topic');
		$this->load->model('reply_model','reply');
	}
	
	public function tome() {
	    
	    $this->check_page_login();
	    
	    $this->load->library('pagination');
	    $limit_num = !empty($_GET['per_page']) ? intval($_GET['per_page']) : 0;
	    
		$this->load->model('topic_model');
		$this->p['poster_id'] = $this->loginer->id;
		$list_topic = $this->topic_model->get_recmd_by_page($limit_num,$this->loginer->id);
		$loginer_id = empty($this->loginer->id) ? 0 : $this->loginer->id;
		$list_topic = $this->topic_model->list_favo_status($list_topic,$loginer_id);
		$this->_data['list_topic'] = $list_topic;
		
	    //分页导航
    	$this->pagination->base_url = $this->page_url($this->p);;
	    $this->pagination->total_rows = $this->topic_model->count;
	    $this->_data['pagelinks'] = $this->pagination->create_links();
	    
	    
	    //当前导航
	    $this->_data['nav_tome'] = ' c ';
	    
    	$this->load->view('topic/recmd',$this->_data);		
	}
	
	public function meto() {
	    
	    $this->check_page_login();
	    
	    $this->load->library('pagination');
	    $limit_num = !empty($_GET['per_page']) ? intval($_GET['per_page']) : 0;
	    
		$this->load->model('topic_model');
		$this->p['poster_id'] = $this->loginer->id;
		$list_topic = $this->topic_model->get_recmd_meto_by_page($limit_num,$this->loginer->id);
		$loginer_id = empty($this->loginer->id) ? 0 : $this->loginer->id;
		$list_topic = $this->topic_model->list_favo_status($list_topic,$loginer_id);
		$this->_data['list_topic'] = $list_topic;
		
	    //分页导航
    	$this->pagination->base_url = $this->page_url($this->p);;
	    $this->pagination->total_rows = $this->topic_model->count;
	    $this->_data['pagelinks'] = $this->pagination->create_links();
	    
	    //当前导航
	    $this->_data['nav_meto'] = ' c ';
	    
    	$this->load->view('topic/recmd_meto',$this->_data);		
	}
	
	function del(){
	    $this->check_ajax_login();
	    if(empty($this->p['id'])) die;
	    $recmd = $this->cm->row('recmd',array('recmd_id'=>$this->p['id']));
        if($recmd->del == 0){
            if($this->loginer->id == $recmd->to_id){
                $this->cm->update('recmd',array('del'=>1),array('recmd_id'=>$this->p['id']));
            }else{
                $this->cm->update('recmd',array('del'=>2),array('recmd_id'=>$this->p['id']));
            }
        }elseif($recmd->del == 1 || $recmd->del == 2){
            $this->cm->update('recmd',array('del'=>3),array('recmd_id'=>$this->p['id']));
        }	   

        ejd('','','reload');
	}
	
	
}

